#pragma once

#include "udpclient.h"
#include "common.h"
#include "trend.h"

class BWProbe : public IUdpClientListener
{
public:

	BWProbe(uint32 upperbound, uint32 lowerbound, uint32 precise);//Bytes/s
	virtual ~BWProbe();

	void Run(const std::string& ip, int port);
	void Stop();

	void NotifyResult(uint32 bw);

	virtual void HandleResult(uint32 sendrate, uint32 recvrate, bool inc, uint32 loss);
	virtual void HandleError(uint32 err_code);

protected:
	bool CheckUpperLimit();

private:
	uint32 m_upperbound;
	uint32 m_lowerbound;
	uint32 m_upperlimt;
	uint32 m_lowerlimt;
	uint32 m_precise;
	uint32 m_currrate;

	UDPClient m_udpClient;
	bool m_bInitguessed;

	uint32 m_starttick;
	uint32 m_seq;

	uint32 m_last_upperbound;
	uint32 m_last_lowerbound;
	uint32 m_last_upperlimt;
	uint32 m_last_lowerlimt;
	uint32 m_last_current;

	SimPearson m_sim;
	bool m_lossmode;
	uint32 m_lossmode_avgspd;
	uint32 m_lossmode_index;
};